package com.home.base.util;

import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.springframework.util.ObjectUtils;

import java.util.concurrent.TimeUnit;

public class SeleniumIeFetchUtil {
   static SeleniumIeFetchUtil instance;
    InternetExplorerDriver webDriver;
    String baseUri="https://cbss.10010.com/essframe";

    public SeleniumIeFetchUtil(){
        if(ObjectUtils.isEmpty(webDriver)){
            this.webDriver=init();
        }
    }

    public static SeleniumIeFetchUtil getInstance(){
        if(ObjectUtils.isEmpty(instance)){
            instance=new SeleniumIeFetchUtil();
        }
        return instance;
    }

    public InternetExplorerDriver init(){
       // System.setProperty("webdriver.chrome.driver",  "f://wb//360//chromedriver.exe");
        System.setProperty("webdriver.ie.driver",  "f://wb//360//IEDriverServer.exe");

        InternetExplorerOptions options = new InternetExplorerOptions();
        options.setPageLoadStrategy(PageLoadStrategy.EAGER);

        //DesiredCapabilities capabilities = new DesiredCapabilities();
       // capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        options.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
       // options.setBinary("C:\\Users\\hcyx\\AppData\\Roaming\\secoresdk\\360se6\\Application\\360se.exe");
        return new InternetExplorerDriver(options);
    }

    public InternetExplorerDriver getWebDriver(){
        if(ObjectUtils.isEmpty(webDriver)){
            return init();
        }
        return this.webDriver;
    }

    public void open( ) {
        webDriver.get(baseUri);
        getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        System.out.println(webDriver.getPageSource());
    }

    public void source( ) {
         //getWebDriver().get(baseUri);
        //getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        try {
            System.out.println(getWebDriver().getTitle());
            System.out.println(getWebDriver().getCurrentUrl());
            System.out.println(getWebDriver().getPageSource());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static void main(String[] args){
        //SeleniumFetchUtil.getInstance().loginYY("","");
    }
}
